package net.lanelife.casino.cms.web.controller;

import javax.servlet.ServletRequest;

import net.lanelife.casino.caipiao.dto.admin.PaymentMerchantCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.PaymentMerchantDTO;
import net.lanelife.casino.caipiao.dto.admin.PaymentMerchantTable;
import net.lanelife.casino.caipiao.dto.admin.PaymentMerchantUpdateDTO;
import net.lanelife.casino.caipiao.entity.PaymentMerchant;
import net.lanelife.casino.caipiao.service.api.IPaymentMerchantService;
import net.lanelife.casino.caipiao.service.api.IPaymentPlatformService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.service.support.IGenericService;
import net.lanelife.casino.common.web.resolver.ViewResolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = PaymentMerchantController.PATH)
public class PaymentMerchantController extends CRUDController<PaymentMerchant, Integer, PaymentMerchantDTO, PaymentMerchantCreateDTO, PaymentMerchantUpdateDTO, PaymentMerchantTable<PaymentMerchantDTO>> {
	
	public static final String PATH = "/payment-merchant";
	
	public PaymentMerchantController() {
		super(PATH);
	}

	@Autowired
	private IPaymentMerchantService paymentMerchantService;
	
	@Autowired
	private IPaymentPlatformService paymentPlatformService;
	
	@Override
	protected IGenericService<PaymentMerchant, Integer> getService() {
		return paymentMerchantService;
	}
	
	@Override
	protected void preList(Model model, ServletRequest request) throws Exception {
		model.addAttribute("paymentPlatformList", paymentPlatformService.findAll());
	}

	@Override
	protected void preCreate(Model model, PaymentMerchantCreateDTO createDTO) throws Exception {
		model.addAttribute("paymentPlatformList", paymentPlatformService.findAll());
	}

	@Override
	protected void preUpdate(Model model, PaymentMerchantUpdateDTO updateDTO) throws Exception {
		model.addAttribute("paymentPlatformList", paymentPlatformService.findAll());
	}

	
	@RequestMapping(value = { "/available:{available}/{id}" }, method = RequestMethod.GET)
	public String available(@PathVariable Integer id, @PathVariable Boolean available) throws Exception {
		paymentMerchantService.update(id, available);
		return ViewResolver.getView(PATH + "/list");
	}
	

}
